<!DOCTYPE html>
<html lang = "pt-BR">
    <head>
        <?php
        session_start();
        include_once'bloco/head.php';
        include_once '../control/conexao.php';
        include_once '../control/valida_sessao.php';

        function __autoload($classe) {
            include_once"../model/{$classe}.class.php";
        }
        ?>
        <link href="bootstrap/css/morris.css" rel="stylesheet">
    </head>
    <body>      
        <div id="wrapper">
            <?php include_once'bloco/navbar.php';
            include_once '../control/valida_perfil.php';
            ?>
            <div id="page-wrapper">
                <?php include_once 'bloco/banner.php';?>                  
                
                <div class="row">
                    <div class="col-lg-12"> 
                        <div class=" panel panel-success">                            
                            <div class="panel-heading">
                                <p class="panel-title"><i class = "glyphicon glyphicon-file"></i> Relatório de: <?php echo date('d/m/Y') ?> </p>
                            </div>
                            <div class="panel-body">
                                <div class="row">                                    
                                    <?php
                                    $data1 = date("Y-m-d", strtotime($_GET['data1']));
                                    $data2 = date("Y-m-d", strtotime($_GET['data2']));

                                    $data_inicial = date("d/m/Y", strtotime($_GET['data1']));
                                    $data_final = date("d/m/Y", strtotime($_GET['data2']));

                                    $empresa = new empresa();
                                    $empresaDAO = new empresaDAO();

                                    $emp = count($empresaDAO->listar($empresa, null));
                                    $emp2 = count($empresaDAO->listar_por_data($data1, $data2));

                                    $arTop5 = $empresaDAO->listar_top5($data1, $data2);

                                    $vagaDAO = new vagaDAO();
                                    $arQtdVaga = $vagaDAO->listar_top5($data1,$data2);
                                    ?>
                                    <div class="col-lg-12">
                                        <table class="table">
                                            <tr>
                                                <td>Total de Empresas Cadastradas: </td>
                                                <td><?php echo utf8_encode($emp) ?></td>
                                            </tr>
                                            <tr>
                                                <td>Empresas Cadastradas Entre: <?php echo $data_inicial . " e " . $data_final ?></td>
                                                <td><?php echo utf8_encode($emp2) ?></td>
                                            </tr>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class=" panel panel-success">
                            <div class="panel-heading">
                                <p class="panel-title"><i class = "glyphicon glyphicon-file"></i> Top 5 Empresas que mais disponibilizaram vagas entre: <?php echo $data_inicial . " e " . $data_final ?></p>
                            </div>
                            <div class="panel-body">
                                <div class="row">
                                    <div class="col-md-12">
                                        <table class="table">
                                            <tr>
                                                <td align="center"><strong>Classificação</strong></td>
                                                <td align="center"><strong>Empresa</strong></td>
                                                <td align="center"><strong>Quantidade de Vagas</strong></td>
                                            </tr>
                                            <?php
                                            for ($i = 0; $i < count($arQtdVaga); $i++) {
                                                ?>
                                                <tr>
                                                    <td align="center"><?php echo $i + 1 . "º" . " lugar"; ?></td>
                                                    <td align="center"><?php echo utf8_encode($arTop5[$i]->empresa_sigla) ?></td>
                                                    <td align="center"><?php echo $arQtdVaga[$i] ?></td>
                                                </tr>
                                            <?php } ?>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">                        
                        <div class=" panel panel-success">
                            <div class="panel-heading">
                                <p class="panel-title"><i class="glyphicon glyphicon-stats"></i> Vagas Disponibilizadas Entre <?php echo $data_inicial . " e " . $data_final ?></p>
                            </div>
                            <div class="panel-body">
                                <div class="row">
                                    <div class="col-lg-12">
                                        <table class="table">
                                            <?php
                                            $vaga = new vaga();
                                            $vag1 = count($vagaDAO->listar($vaga, null, null));
                                            $vag2 = count($vagaDAO->listar_por_data($data1,$data2));
                                            ?>
                                            <tr>
                                                <td>Total de Vagas Disponibilizadas: </td>
                                                <td><?php echo $vag1; ?></td>
                                            </tr>
                                            <tr>
                                                <td>Vagas Disponibilizadas Entre: <?php echo $data_inicial . " e " . $data_final ?></td>
                                                <td><?php echo utf8_encode($vag2) ?></td>
                                            </tr>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">                        
                        <div class=" panel panel-success">
                            <div class="panel-heading">
                                <p class="panel-title"><i class="glyphicon glyphicon-stats"></i> Processos de Estágio entre: <?php echo $data_inicial . " e " . $data_final ?></p>
                            </div>
                            <div class="panel-body">
                                <div class="row">
                                    <div class="col-md-12">
                                        <table class="table">
                                            <?php
                                                $processoDAO = new processoDAO();
                                                $processo = $processoDAO->listarParaRelatorio($data1, $data2);
                                                ?>
                                            <tr>
                                                <td>Processos de Estágio Iniciados</td>
                                                <td><?php echo $processo[0] ?></td>
                                            </tr>
                                            <tr>
                                                <td>Processos de Estágio Encerrados</td>
                                                <td><?php echo $processo[1] ?></td>
                                            </tr>
                                        </table>
                                    </div>                                    
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php
        include_once'bloco/scripts.php';
        ?>
        <script src="bootstrap/js/raphael.js"></script>
        <script src="bootstrap/js/morris/morris.js"></script>
        <script src="bootstrap/js/morris/grafico.js"></script>      
        <script>
            var url = "../control/ajax_buscar_empresas.php";
            $.getJSON(url, function(json) {
                Morris.Bar({
                    element: 'bar-chart',
                    data: json,
                    xkey: ['sigla'],
                    ykeys: ['vagas'],
                    labels: ['Vagas', 'Num Vagas'],
                    hideHover: true,
                    barColors: ['#3CB371'],
                    fillOpacity: 0.6,
                });
            })
            $.getJSON(url, function(json) {
                Morris.Line({
                    element: 'line-chart',
                    data: json,
                    xkey: ['sigla'],
                    ykeys: ['vagas'],
                    labels: ['Vagas'],
                    hideHover: true,
                    barColors: ['green'],
                    fillOpacity: 1.0,
                    parseTime: false,
                    smooth: false,
                    gridTextColor: 'black',
                    gridTextSize: '12px',                    
                    ymin: '0',
                    ymax: '8',
                    lineWidth: '5px',
                    lineColors: ['#3CB371'],
                });
            })
        </script>
    </body>
</html>